package Topic;

import Utils.ConnectionFactoryUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @ClassName Producer
 * @Description TDD
 * @Author 混沌酱
 * @Date 2023-10-10 17:17
 * @Version 1.0
 **/
public class Producer {

    /**
     *  发送消息	匹配成功的条件
     *  #.A	A的左边可以任意多个单词，右边不可以有单词
     *  A.#	A的右边可以任意多个单词，左边不可以有单词
     *  #.A.#	A的左边和右边都可以任意多个单词
     *  *.A	A的左边有且只能有一个单词，右边不可以有单词
     *  A.*	A的右边有且只能有一个单词，左边不可以有单词
     *  *.A.*	A的左边和右边都有且只能有一个单词
     **/

    private final static String ROUTE_NAME = "exchange_topic";

    public static void main(String[] args) throws IOException, TimeoutException {

        // 1、建立工厂连接
        Connection connection = ConnectionFactoryUtil.getConnection();

        // 2、建立信道
        Channel channel = connection.createChannel();

        // 3、建立交换机
        channel.exchangeDeclare("exchange_topic", BuiltinExchangeType.TOPIC, true);


        // 4、创建队列
        channel.queueDeclare("SEND_MAIL3", true, false, false, null);
        channel.queueDeclare("SEND_MESSAGE3", true, false, false, null);
        channel.queueDeclare("SEND_STATION3", true, false, false, null);


        // 5、交换机绑定队列
        channel.queueBind("SEND_MAIL3",ROUTE_NAME,"#.big.#");
        channel.queueBind("SEND_MESSAGE3",ROUTE_NAME,"#.middle.#");
        channel.queueBind("SEND_STATION3",ROUTE_NAME,"#.small.#");

        // 6、发送消息
        channel.basicPublish(ROUTE_NAME, "big.middle", null, ("双十一大促销活动--全场买一送一").getBytes());
        channel.basicPublish(ROUTE_NAME, "small.middle",null, ("小促销活动--满1000立减200").getBytes());


    }
}
